//
//  Config.h
//  basic
//
//  Created by Jack on 2016/11/15.
//  Copyright © 2016年 Jack. All rights reserved.
//

#ifndef Config_h
#define Config_h

/**
 *  系统版本
 */
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define   IOS7    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")
#define   IOS8    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
#define   IOS9    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")
#define   IOS10    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")

/**
 *  APP版本号
 */
#define   APP_VERSON   ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])



/**
 *  角度转换为弧度
 */
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)


/**
 *  RGB
 */
#define UIColorFromRGB(rgbValue) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define UIColorFromRGBAlpha(rgbValue,alphaValue) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]


/**
 *  APP颜色
 */
#define COLOR_BG                 UIColorFromRGB(0xf5f5f5)
#define COLOR_NAVI               UIColorFromRGB(0xa7a7a7)
#define COLOR_CONTENT            UIColorFromRGB(0xa7a7a7)
#define COLOR_TITLE              UIColorFromRGB(0x3c3c3c)
#define COLOR_TITLE2             UIColorFromRGB(0x8d8d8d)
#define COLOR_THEME              UIColorFromRGB(0xf94c08)
#define COLOR_PLACEHOLDER        UIColorFromRGB(0xc7c7cd)
#define COLOR_CLEAR              [UIColor clearColor]
#define COLOR_BORDER             UIColorFromRGB(0xdfdfdf)

#define COLOR_CIRCLE_BG          UIColorFromRGB(0xeeeeee)
#define COLOR_CIRCLE_BG1         UIColorFromRGB(0x2fc5f6)
#define COLOR_CIRCLE_BG2         UIColorFromRGB(0xfeb23c)
#define COLOR_CIRCLE_BG3         UIColorFromRGB(0xfe6e6e)



/**
 *  屏幕宽高
 */
#define kMainScreenFrameRect         [[UIScreen mainScreen] bounds]
#define kMainScreenWidth             kMainScreenFrameRect.size.width
#define kMainScreenHeight            kMainScreenFrameRect.size.height
#define kMainScreenHeightWithoutBar  (kMainScreenFrameRect.size.height - 64)

//view水平右边界x值
#define kNextXFrom(view)    view.frame.origin.x + view.frame.size.width
//view垂直底边界y值
#define kNextYFrom(view)    view.frame.origin.y + view.frame.size.height

#define kMarginLeftWidth 16.0


/**
 *  img
 */
#define ImageWithName(name)\
[UIImage imageNamed:name]

#define ImageWithFile(pathN)\
[UIImage imageWithContentsOfFile:pathN]


/**
 *  边框
 */
#define ViewLayerBorder(view,color,width)\
\
view.layer.borderColor = color.CGColor;\
view.layer.borderWidth = width;

/**
 *  裁圆
 */
#define ViewLayerCorner(view,radius)\
\
view.layer.cornerRadius = radius;\
view.layer.masksToBounds = YES;


/**
 *  url
 */
#define UrlWithString(string)\
[NSURL URLWithString:string]

/**
 *  NSNotificationCenter
 */
#define NotificationCenter [NSNotificationCenter defaultCenter]

/**
 *  DLog
 */
#ifdef DEBUG
#ifndef DLog
#   define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}
#endif
#ifndef ELog
#   define ELog(err) {if(err) DLog(@"%@", err)}
#endif
#else
#ifndef DLog
#   define DLog(...)
#endif
#ifndef ELog
#   define ELog(err)
#endif
#endif


/**
 *  NIB
 *
 */

#define NIBWITHCLASS(nibClass)\
\
[UINib nibWithNibName:NSStringFromClass([nibClass class]) bundle:nil]


/**
 *  单例
 */

#define DEFINE_SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;


#define DEFINE_SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}


/**
 *  NIBVIEW
 */

#define DEFINE_NIBVIEW_FOR_HEADER(className) \
\
+(className *)instanceNibView;



#define DEFINE_NIBVIEW_FOR_CLASS(className) \
\
+(className *)instanceNibView{\
NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([className class]) owner:nil options:nil];\
className *view = nibView.firstObject;\
return view;\
}




/**
 *  UIImageView sd_setImg
 *
 *  @param imageView           imageView
 *  @param imageURLStr         urlStr
 *  @param placeholderImageStr placeholderImageStr
 *
 */
#define DEFINE_UIIMAGEVIEW_SD_SETIMG(imageView,weakSelfName,imageURLStr,placeholderImageStr) \
\
__weak UIImageView *(weakSelfName) = imageView;\
\
[imageView sd_setImageWithURL:UrlWithString([imageURLStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]) placeholderImage:ImageWithName(placeholderImageStr) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {\
\
if (cacheType == SDImageCacheTypeNone) {\
CATransition *animation = [CATransition animation];\
animation.duration = 0.32;\
animation.timingFunction = UIViewAnimationCurveEaseInOut;\
animation.type = kCATransitionFade;\
animation.removedOnCompletion = YES;\
[[weakSelfName layer] addAnimation:animation forKey:@"animation"];\
}\
}];



/**
 *  ViewContentMode
 */
#define ViewContentModeFit(view)\
view.contentMode = UIViewContentModeScaleAspectFit

//提示
#define MBHudMessage(tipMsg)\
[MMTextHud showText:tipMsg]


// block self
#define WEAKSELF typeof(self) __weak weakSelf = self;
#define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf;


//page
#define PER_PAGE_SIZE                   10
#define PER_PAGE_SIZE_20                20

#define PER_DISCUZ_PAGE_SIZE            10



#define kRightTableView_MaxWidth      (kMainScreenWidth/5 *3) //打开右侧窗时，中视图(右视图)露出的宽度
#define kRightTableView_TopHeight     (120)//打开右侧窗时，top高度
//#define kRightTableView_BottomHeight  (80)//打开右侧窗时，bottom高度



#define kNote_Message_234G        @"您正在使用非WIFI网络，是否要继续？"
#define kNote_Message_NONETWORK   @"当前网络不可用"


#define kExpose_Admin_Header      @"http://img.jjntv.cn/images/nohead.jpg"

#define kDiscuz_MaxImage          (9)

//提示
#undef AlertMessage
#define AlertMessage(tipMsg)    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:\
tipMsg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];\
[alertView show];\
RELEASE_SAFELY(alertView)

#undef AlertMessageArc
#define AlertMessageArc(tipMsg)    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:\
tipMsg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];\
[alertView show];


#endif /* Config_h */
